Shader "Hidden/VPR/Blur"
{
    HLSLINCLUDE
    
    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    TEXTURE2D(_SourceTex);
    //纹理中的单像素尺寸  
    float4 _SourceTex_TexelSize;  
    SamplerState sampler_SourceTex;
    float4 _BlurRadius;
    //sampler_BlitTex
    struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                
                float4 vertex : SV_POSITION;
                float2 uv1 : TEXCOORD0; //存储两个uv坐标
                float2 uv2 : TEXCOORD1; //存储两个uv坐标
                float2 uv3 : TEXCOORD2; //存储两个uv坐标
                float2 uv4 : TEXCOORD3; //存储两个uv坐标
                float2 uv5 : TEXCOORD4;
            };
    ENDHLSL
    SubShader
    {
        // No culling or depth
        Cull Off ZWrite Off ZTest Always
        Pass
        {
            Name "Blur Horizontal"
            HLSLPROGRAM
            #pragma vertex vert_HorizontalBlur
            #pragma fragment frag_HorizontalBlur
            v2f vert_HorizontalBlur(appdata v)
            {
                v2f o;
                _BlurRadius *= _SourceTex_TexelSize.xyxy;
                o.vertex = TransformObjectToHClip(v.vertex.xyz);
                o.uv1=v.uv + _BlurRadius.xy * half2(1,0) * -2.0;
                o.uv2=v.uv + _BlurRadius.xy * half2(1,0) * -1.0;
                o.uv3=v.uv ;
                o.uv4=v.uv+ _BlurRadius.xy * half2(1,0) * 1.0;
                o.uv5=v.uv+ _BlurRadius.xy * half2(2,0) * 2.0;
        
                return o;
            }
            half4 frag_HorizontalBlur (v2f i) : SV_Target
            {
                half4 s = 0;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv1)* 0.05;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv2)* 0.25;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv3)* 0.40;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv4)* 0.25;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv5)* 0.05;
                
                return s;
            }
            ENDHLSL
        }
        Pass
        {
            Name "Blur Vorizontal"
            HLSLPROGRAM
            #pragma vertex vert_VorizontalBlur
            #pragma fragment frag_VorizontalBlur
            v2f vert_VorizontalBlur(appdata v)
            {
                v2f o;
                _BlurRadius *= _SourceTex_TexelSize.xyxy;  
                o.vertex = TransformObjectToHClip(v.vertex.xyz);
                o.uv1=v.uv + _BlurRadius.zw * half2(0,1) * -2.0;
                o.uv2=v.uv + _BlurRadius.zw * half2(0,1) * -1.0;
                o.uv3=v.uv ;
                o.uv4=v.uv+ _BlurRadius.zw * half2(0,1) * 1.0;
                o.uv5=v.uv+ _BlurRadius.zw * half2(0,1) * 2.0;
        
                return o;
            }
            half4 frag_VorizontalBlur (v2f i) : SV_Target
            {
                half4 s = 0;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv1)* 0.05;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv2)* 0.25;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv3)* 0.40;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv4)* 0.25;
                s += _SourceTex.Sample(sampler_SourceTex, i.uv5)* 0.05;
                
                return s;
            }
            ENDHLSL
        }
    }
}